for key, typ in XENAPI_CFG_TYPES.items():
val = sxp.child_value(sxp_cfg, key)
if val is not None:
- cfg[key] = typ(val)
+ try:
+ cfg[key] = typ(val)
+ except (ValueError, TypeError), e:
+ log.warn('Unable to convert type value for key: %s' % key)
# Convert deprecated options to current equivalents.
finally:
self.domains_lock.release()
+ def autostart_domains(self):
+ """ Autostart managed domains that are marked as such. """
+
+ need_starting = []
+
+ self.domains_lock.acquire()
+ try:
+ for dom_uuid, dom in self.managed_domains.items():
+ if dom and dom.state == DOM_STATE_HALTED:
+ on_xend_start = dom.info.get('on_xend_start', 'ignore')
+ auto_power_on = dom.info.get('auto_power_on', False)
+ should_start = (on_xend_start == 'start') or auto_power_on
+ if should_start:
+ need_starting.append(dom_uuid)
+ finally:
+ self.domains_lock.release()
+
+ for dom_uuid in need_starting:
+ self.domain_start(dom_uuid, False)
+
def cleanup_domains(self):
"""Clean up domains that are marked as autostop.
Should be called when Xend goes down. This is currently
from xen.xend import Vifctl
from xen.xend.XendLogging import log
from xen.xend.XendClient import XEN_API_SOCKET
+from xen.xend.XendDomain import instance as xenddomain
from xen.web.SrvDir import SrvDir
from SrvRoot import SrvRoot
def add(self, server):
self.servers.append(server)
- def cleanup(self, signum = 0, frame = None):
+ def cleanup(self, signum = 0, frame = None, reloading = False):
log.debug("SrvServer.cleanup()")
self.cleaningUp = True
for server in self.servers:
server.shutdown()
except:
pass
+
+ # clean up domains for those that have on_xend_stop
+ if not reloading:
+ xenddomain().cleanup_domains()
+
self.running = False
+
def reloadConfig(self, signum = 0, frame = None):
log.debug("SrvServer.reloadConfig()")
self.reloadingConfig = True
- self.cleanup(signum, frame)
+ self.cleanup(signum, frame, reloading = True)
def start(self, status):
# Running the network script will spawn another process, which takes
status.close()
status = None
+ # Reaching this point means we can auto start domains
+ try:
+ xenddomain().autostart_domains()
+ except Exception, e:
+ log.exception("Failed while autostarting domains")
+
# loop to keep main thread alive until it receives a SIGTERM
self.running = True
while self.running: